Skip to content

Conversation

@esc10946
Copy link
Contributor

@esc10946 esc10946 commented Jan 8, 2026

🚀 이슈 번호

Resolve: {#2284}

🧩 문제 해결

스스로 해결:

🔎 접근 과정

문제 해결을 위한 접근 방식을 설명해주세요.

  • 🔹 어떤 알고리즘을 사용했는지 : dp
  • 🔹 어떤 방식으로 접근했는지: 처음에는 시간복잡도 계산안하고 바로 bfs로 풀어봤는데 시간 제한에 걸렸습니다. bfs로 풀면 n^2 * n^2 로 n^4의 시간복잡도를 갖게 됩니다. 따라서 해당 문제는 dp로 다시 풀었습니다.
  • 메모리제이션과 재귀를 통해 문제를 해결하였습니다.

⏱️ 시간 복잡도

시간 복잡도 분석을 작성해주세요.
최악의 경우 수행 시간은 어느 정도인지 분석합니다.

  • Big-O 표기법: O(N^2)
  • 이유:

💻 구현 코드

#include <bits/stdc++.h>

using namespace std;

int direction[4][2] = { {-1,0}, {0,-1}, {1, 0}, {0, 1} };
vector<vector<int>> Map;
vector<vector<int>> dp;
int n;

int GetDis(int y, int x) {
    int ret = 1;
    if (dp[y][x] != 0) return dp[y][x]; //값이 이미 있으면 바로 값을 반환합니다.

    dp[y][x] = 1;
    for (auto dir : direction) {
        int ny = dir[0] + y;
        int nx = dir[1] + x;

        if (nx < 0 || ny < 0 || nx >= n || ny >= n) continue;
        if (Map[ny][nx] > Map[y][x]) { 
            dp[y][x] = max(dp[y][x], GetDis(ny, nx) + 1);
        }
    }
    return dp[y][x];
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n;

    Map.resize(n, vector<int>(n));
    dp.resize(n, vector<int>(n));

    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            cin >> Map[i][j];
        }
    }

    int maxDis = 1;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            maxDis = max(maxDis, GetDis(i, j));
        }
    }

    cout << maxDis << endl;
    return 0;

@esc10946 esc10946 linked an issue Jan 8, 2026 that may be closed by this pull request
@esc10946 esc10946 merged commit 39b4061 into main Jan 12, 2026
2 checks passed
@esc10946 esc10946 deleted the hojun/2284/2 branch January 12, 2026 22:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

260108 : 코딩테스트

2 participants